/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import {
  ArgumentMetadata,
  HttpException,
  HttpStatus,
  Injectable,
  PipeTransform,
} from '@nestjs/common';
import { ClassConstructor, plainToInstance } from 'class-transformer';
import { Validate } from 'class-validator';
@Injectable()
export class LoginPipe implements PipeTransform {
  async transform(value: any, metadata: ArgumentMetadata) {
    const obj = plainToInstance(
      metadata.metatype as ClassConstructor<any>,
      value,
    );
    const errors = await Validate(obj);
    if (errors.length) throw new HttpException(errors, HttpStatus.BAD_REQUEST);
    console.log(errors);
    return value;
  }
}
